package com.yituo.mjworld.mvc.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * 阿里云服务接口
 */
@Service
public class AliyunServiceImpl {

  /**
   * 获取物流信息
   *
   * @return
   */
  public JSONObject getLogisticsInfo(String transportId) throws IOException {
    String url = "http://jisukdcx.market.alicloudapi.com/express/query?number=" + transportId + "&type=auto";
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    httpGet.setHeader("Authorization","APPCODE "+AliyunConfig.APP_CODE);
    // 执行请求
    HttpResponse response = httpClient.execute(httpGet);
    JSONObject result = (JSONObject) JSONObject.parse(EntityUtils.toString(response.getEntity(), "utf-8"));
    return result;
  }
}
